/**
 * 创建reducer
 */

import { ADD, SUB } from "./actions"

// //  初始化购物车默认数据
// const initState = {
//   num1: 10,
//   num2: 20,
//   num3: 30
// }

export default function reducer (state, action) {
  const newState = { ...state }
  switch (action.type) {
    // 商品数量加一=>加的那个商品？
    case ADD:
      newState[action.pname]++
      if (action.ot) newState[action.pname] += action.ot
      return newState
    // 商品数量减一 
    case SUB:
      newState[action.pname]--
      return newState
    default:
      return state
  }
}